package com.ewili.x.special.service.data.impl;

import com.ewili.framework.utils.ObjectHttpClientUtils;
import com.ewili.x.special.dao.inter.AmountStockDao;
import com.ewili.x.special.dao.inter.StockDao;
import com.ewili.x.special.service.data.inter.AmountStockService;
import com.ewili.x.special.task.thread.inter.AmountStockThreadTask;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author wonder
 */
@Service
public class AmountStockServiceImpl implements AmountStockService {

    @Autowired
    private StockDao stockDao;

    @Autowired
    private AmountStockDao amountStockDao;


    @Autowired
    private AmountStockThreadTask amountStockThreadTask;


    @Override
    public void spide() {
        amountStockDao.deleteAll();
        amountStockThreadTask.doSpide();
    }

    @Override
    public void spideThreeDaysAmountAddRate() {
        String baseUrl = "http://push2.eastmoney.com/api/qt/clist/get?cb=jQuery112306534880505254755_1630042929641&fid=f268&po=0&pz=50&pn=1&np=1&fltt=2&invt=2&ut=b2884a393a59ad64002292a3e90d46a5&fs=m%3A0%2Bt%3A6%2Bf%3A!2%2Cm%3A0%2Bt%3A13%2Bf%3A!2%2Cm%3A0%2Bt%3A80%2Bf%3A!2%2Cm%3A1%2Bt%3A2%2Bf%3A!2%2Cm%3A1%2Bt%3A23%2Bf%3A!2%2Cm%3A0%2Bt%3A7%2Bf%3A!2%2Cm%3A1%2Bt%3A3%2Bf%3A!2&fields=f12%2Cf14%2Cf2%2Cf127%2Cf267%2Cf268%2Cf269%2Cf270%2Cf271%2Cf272%2Cf273%2Cf274%2Cf275%2Cf276%2Cf257%2Cf258%2Cf124%2Cf1%2Cf13";
        int pageNums = ObjectHttpClientUtils.formatEastMoneyJsonObject(baseUrl,"data").getInt("total");
        for (int i =1;i<=pageNums;i++){
            String url = "http://push2.eastmoney.com/api/qt/clist/get?cb=jQuery112306534880505254755_1630042929641&fid=f268&po=&pz=50&pn="+i+"&np=1&fltt=2&invt=2&ut=b2884a393a59ad64002292a3e90d46a5&fs=m%3A0%2Bt%3A6%2Bf%3A!2%2Cm%3A0%2Bt%3A13%2Bf%3A!2%2Cm%3A0%2Bt%3A80%2Bf%3A!2%2Cm%3A1%2Bt%3A2%2Bf%3A!2%2Cm%3A1%2Bt%3A23%2Bf%3A!2%2Cm%3A0%2Bt%3A7%2Bf%3A!2%2Cm%3A1%2Bt%3A3%2Bf%3A!2&fields=f12%2Cf14%2Cf2%2Cf127%2Cf267%2Cf268%2Cf269%2Cf270%2Cf271%2Cf272%2Cf273%2Cf274%2Cf275%2Cf276%2Cf257%2Cf258%2Cf124%2Cf1%2Cf13";
            amountStockThreadTask.spideThreeDaysAmountAddRate(url);
        }
    }
}
